package com.gdth.bank.presenter;

import java.util.List;

import rx.Subscriber;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

import com.gdth.bank.model.TAppBfrjJtcyCpxqModel;
import com.gdth.bank.view.TAppBfrjJtcyCpxqView;
import com.gdth.database.bean.TAppBfrjCpxq;

public class TAppBfrjJtcyCpxqPresenter {
    private TAppBfrjJtcyCpxqView mTAppBfrjJtcyCpxqView;
    private TAppBfrjJtcyCpxqModel mTAppBfrjJtcyCpxqModel;
    
    public TAppBfrjJtcyCpxqPresenter(TAppBfrjJtcyCpxqView mTAppBfrjJtcyCpxqView){
    	this.mTAppBfrjJtcyCpxqView = mTAppBfrjJtcyCpxqView;
    	mTAppBfrjJtcyCpxqModel= new TAppBfrjJtcyCpxqModel();
    	
    }
    
    public void savejtcyxxCpxq(List<TAppBfrjCpxq>   mTAppBfrjCpxqList){
    	mTAppBfrjJtcyCpxqView.showProgressDialog("保存中");
    	mTAppBfrjJtcyCpxqModel.savejtcyCpxq(mTAppBfrjCpxqList)
			.subscribeOn(Schedulers.io())
			.unsubscribeOn(Schedulers.io())
			.observeOn(AndroidSchedulers.mainThread())
			.subscribe(new Subscriber<List<TAppBfrjCpxq>>(){

				@Override
				public void onCompleted() {
					// TODO Auto-generated method stub
					mTAppBfrjJtcyCpxqView.hideProgressDialog();
				}

				@Override
				public void onError(Throwable arg0) {
					// TODO Auto-generated method stub
					mTAppBfrjJtcyCpxqView.showMessage("保存本地");
				}

				@Override
				public void onNext(List<TAppBfrjCpxq> arg0) {
					// TODO Auto-generated method stub
					mTAppBfrjJtcyCpxqView.saveSuccess(arg0);
				}
				
			});
    }
    
    public void getjtcyxxCpxq(String jtuuid){
    	mTAppBfrjJtcyCpxqView.showProgressDialog("加载中");
    	mTAppBfrjJtcyCpxqModel.getjtcyxxCpxq(jtuuid)
			.subscribeOn(Schedulers.io())
			.unsubscribeOn(Schedulers.io())
			.observeOn(AndroidSchedulers.mainThread())
			.subscribe(new Subscriber<List<TAppBfrjCpxq>>(){

				@Override
				public void onCompleted() {
					// TODO Auto-generated method stub
					mTAppBfrjJtcyCpxqView.hideProgressDialog();
				}

				@Override
				public void onError(Throwable arg0) {
					// TODO Auto-generated method stub
				}

				@Override
				public void onNext(List<TAppBfrjCpxq> arg0) {
					// TODO Auto-generated method stub
					if(arg0.size()>0){
						mTAppBfrjJtcyCpxqView.getjtcyCpxqXx(arg0);
					}
				}
				
			});
    }
    
    public void getjtcyxxCpxqId(Long id){
    	mTAppBfrjJtcyCpxqModel.getjtcyxxCpxqId(id)
			.subscribeOn(Schedulers.io())
			.unsubscribeOn(Schedulers.io())
			.observeOn(AndroidSchedulers.mainThread())
			.subscribe(new Subscriber<TAppBfrjCpxq>(){

				@Override
				public void onCompleted() {
					// TODO Auto-generated method stub
					mTAppBfrjJtcyCpxqView.hideProgressDialog();
				}

				@Override
				public void onError(Throwable arg0) {
					// TODO Auto-generated method stub
				}

				@Override
				public void onNext(TAppBfrjCpxq arg0) {
					// TODO Auto-generated method stub
					
				}
				
			});
    }
}
